Skip to content

Reuse Slug atlas projections during compilation - #171

Open
kostyafarber wants to merge 5 commits into
mainfrom
agent/slug-atlas-projection-reuse
Open

Reuse Slug atlas projections during compilation#171
kostyafarber wants to merge 5 commits into
mainfrom
agent/slug-atlas-projection-reuse

Conversation

@kostyafarber

Copy link
Copy Markdown
Collaborator

Summary

  • prepare one immutable GlyphProjectionSet for each authored Slug compilation and reuse it for weight collection, roots, component closures, exact sources, and fallback resolution
  • share authored layers and equal interpolation bases through Arc, while keeping resolved source glyphs root-local so reuse cannot survive edits or inflate full-font temporary memory
  • add phase profiling to the existing Bridge.prepareSlugAtlas path plus a release profiler that verifies atlas counts across cold, resumed, and warm preparations
  • add regression coverage for shared component/basis reuse and byte-for-byte equality between per-root and shared-set atlas construction

Fraunces release results

Same Ryzen 5 5500U, same /home/firmclaw/fraunces.shift, through Bridge.prepareSlugAtlas(256):

Revision Cold prepare Resumed first prepare Warm p50 Warm p95
47fc8c01 526.811 ms 688.788 ms 544.630 ms 546.411 ms
This PR 97.970 ms 242.474 ms 100.640 ms 101.470 ms

Warm p50 improves 5.41x (81.5%). Output is unchanged at 699 roots, 1,290 atlas glyphs, 12,713 curves, 998 components, and 2,190,648 bytes. The resumed result includes 141.493 ms of lazy acquisition; warm native atlas compilation is approximately 99–101 ms.

Parallelism is intentionally deferred: duplicate-work removal already exceeds the sub-second target, and deterministic parallel atlas merging would add memory and complexity before measurement justifies it.

Verification

  • commit hooks: Cargo check/fmt/clippy/test, Oxfmt, Oxlint, deadcode, and Vitest
  • cargo test -p shift-font
  • cargo test -p shift-slug --all-features
  • cargo clippy -p shift-font -p shift-slug -p shift-bridge --all-targets --all-features -- -D warnings
  • pnpm test:native
  • same-machine before/after release profiler through the native bridge API

python3 scripts/context-drift-check.py still reports the existing unrelated app documentation errors described on main. An authored Source Han .shift corpus was not available on this machine; the implementation avoids a complete resolved-glyph table and retains only root-local resolved source results.

@kostyafarber

Copy link
Copy Markdown
Collaborator Author

Follow-up startup profile for e94c13bd (release NAPI, /home/firmclaw/fraunces.shift, five warm-filesystem samples):

Path Inspect p50 Open/resume p50 Complete atlas p50 Complete-preview p50
Fresh hydrate 32.4 ms 420.8 ms 97.2 ms 551.5 ms
Retained clean resume 32.3 ms 52.1 ms 238.0 ms 322.3 ms

The working-document open phase improves 8.1x; inspect + open + complete atlas improves 41.6%. The resumed atlas includes lazy SQLite layer acquisition. This measures a complete atlas, not placeholders; renderer transfer/upload is outside this harness. In the app, prepareOpen() now starts the utility while the launcher/dialog is active, so the observed 1.36 s cold utility boot can overlap source selection. The next app-log run should confirm the process is already ready before the dialog returns and that only one inspect-package line occurs.

@kostyafarber

Copy link
Copy Markdown
Collaborator Author

Background atlas preparation profile for 6c48c586 (Fraunces, release NAPI):

Phase Fresh hydrate Clean resume
Open response 425.3 ms 53.0 ms
Authored compilation dispatched after response 99.9 ms 238.1 ms
Final aligned prepareSlugAtlas(256) 2.3 ms 2.1 ms

The native profiler independently measured resumed authored compilation at 245.2 ms and aligned preparation at 1.72 ms. The compilation request is now sent from main only after the open response is received, then runs in utility while the workspace window and WebGPU start. The previously observed renderer/window interval was about 500 ms, so this work should be hidden rather than added to open latency. The grid still waits for the complete atlas; no placeholder or partial geometry path was introduced. Output remains 699 roots, 1,290 atlas glyphs, 12,713 curves, 998 components, and 2,190,648 bytes.

@kostyafarber

Copy link
Copy Markdown
Collaborator Author

Follow-up 09d52877 applies the performance-fixture pattern used by Fontations/Zed/Vello/VS Code: correctness remains in ordinary fixture tests, timings remain in an external repeated benchmark, and no profiling DTOs enter the product APIs.

Native changes:

  • read each SQLite layer directory fact once and reuse it for bounded payload/component batches;
  • retain unchanged layer-owner/source indexes during payload replacement instead of removing and reinserting them;
  • make profile-slug-atlas.mjs run independent clean-resume samples and report p50/p95 (<source> [warm-iterations] [resume-iterations]).

Fraunces release samples:

  • clean resume: ~51.0 ms p50;
  • resumed authored preparation: 227.760 ms p50, 230.235 ms p95 (previous projection-reuse baseline 242.474 ms);
  • aligned preparation: ~1.18 ms p50;
  • output unchanged: 699 roots, 1,290 atlas glyphs, 12,713 curves, 998 components, 2,190,648 bytes.

All commit hooks, Rust tests, native bridge tests, and Clippy passed. The existing documentation drift checker still reports the same 13 unrelated main-branch errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant